#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class segment_tree {
	int LIMIT = 80001;
	int cnt = 1;
	vector<int> left, right;
        vector<long> sum, add;

	void lazy(int i, long v, int n)
	{
		sum[i] += v * n;
		add[i] += v;
	}

	void up(int i, int l, int r)
	{
		sum[i] = sum[l] + sum[r];
	}

	void down(int i, int ln, int rn)
	{
		if (add[i]) {
			if (left[i] == 0) {
				left[i] = ++cnt;
			}
                        lazy(left[i], add[i], ln);

			if (right[i] == 0) {
				right[i] = ++cnt;
			}
                        lazy(right[i], add[i], rn);

			add[i] = 0;
		}
	}

    public:
	segment_tree() : sum(LIMIT, 0), left(LIMIT, 0), right(LIMIT, 0), add(LIMIT, 0)
	{
	}

	void update(int jobl, int jobr, long v, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			lazy(i, v, r - l + 1);
		} else {
			int mid = (l + r) >> 1;
			down(i, mid - l + 1, r - mid);
			if (jobl <= mid) {
				if (left[i] == 0) {
					left[i] = ++cnt;
				}
				update(jobl, jobr, v, l, mid, left[i]);
			}
			if (mid < jobr) {
				if (right[i] == 0) {
					right[i] = ++cnt;
				}
				update(jobl, jobr, v, mid + 1, r, right[i]);
			}
			up(i, left[i], right[i]);
		}
	}

	long query(int jobl, int jobr, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			return sum[i];
		}
		int mid = (l + r) >> 1;
		down(i, mid - l + 1, r - mid);
		long ans = 0;
		if (jobl <= mid) {
			if (left[i] != 0) {
				ans += query(jobl, jobr, l, mid, left[i]);
			}
		}
		if (mid < jobr) {
			if (right[i] != 0) {
				ans += query(jobl, jobr, mid + 1, r, right[i]);
			}
		}
		return ans;
	}
};

int main()
{
        int n, m;
        cin >> n >> m;
        segment_tree sgt;

        for(int i = 0, op, l, r, v; i < m; i++){
                cin >> op;
                if(op == 1){
                        cin >> l >> r >> v;
                        sgt.update(l, r, v, 1, n, 1);
                }else{
                        cin >> l >> r;
                        cout << sgt.query(l, r, 1, n, 1) << endl;
                }
        }
	return 0;
}